const router = require("koa-router")();
const path = require("path");
const fs = require("fs");
const city = require("../mock/cities.json");
router.get("/trip/airplane", async (ctx, next) => {
  const { start, end } = ctx.query;
  console.log(start, end);
  const url = `${start}-${end}.json`;

  const url1 = path.resolve(__dirname, "../mock", url);

  const result = fs.existsSync(url1);

  if (result) {
    const data = require(url1);
    ctx.body = { code: 200, message: "数据获取成功", data: data };
  } else {
    ctx.body = { code: 404, message: "该飞行暂没有数据支持" };
  }
});

router.get("/city", async (ctx, next) => {
  ctx.body = {
    code: 200,
    data: city,
    message: "ok",
  };
});

module.exports = router;
